<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/plugins/layui/css/layui.css}">
    <style>
        body {
            padding: 10px;
        }

    </style>
</head>
<body>
<div class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">权限名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="roleName" name="roleName" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单类型</label>
        <div class="layui-input-block">
            <input type="radio" lay-filter="menuType-filter" name="menuType" value="M" class="layui-input" title="目录">
            <input type="radio" lay-filter="menuType-filter" name="menuType" value="C" class="layui-input" title="菜单">
            <input type="radio" lay-filter="menuType-filter" name="menuType" value="F" class="layui-input" title="按钮">
        </div>
    </div>

    <input type="hidden" id="parentId" name="parentId">
    <div class="layui-form-item" id="pIdFormItem">
        <label class="layui-form-label">父级菜单</label>
        <div class="layui-input-inline layui-input-wrap">
            <select id="pId">
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">请求地址</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="url" name="url" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">权限标识</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="perms" name="perms" class="layui-input">
            </div>
        </div>
    </div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/plugins/layui/layui.js}"></script>
<script>
    layui.use(function () {
        var form = layui.form;
        var $ = layui.$;

        form.on('radio(menuType-filter)', function(data){
            let menuType = data.elem.value;
            if (menuType == "M") {
                $("#parentId").val("0");
                $("#pIdFormItem").hide();
                $("#url").val("#");

            } else if(menuType == "C") {
                $.ajax({
                    type: "get",
                    url: "/permission/listMenu",
                    data: {
                        menuType: "M"
                    },
                    dataType: "json",
                    success: function (data) {
                    }
                })
            } else if(menuType == "F"){
                $.ajax({
                    type: "get",
                    url: "/permission/listMenu",
                    data: {
                        menuType: "C"
                    },
                    dataType: "json",
                    success: function (data) {
                    }
                })
            }
        })
    })
</script>
</body>
</html>
